'use strict';

const Service = require('egg').Service;

class ShopListService extends Service {
    async getShopList() {
        const { app, service } = this;
        const result = await app.mysql.select('good_list');
        return service.shopList.listThree(result);
    }
    listThree(list, id = 0, baseList = []) {
        const { service } = this;
        //顶层
        for (let item of list) {
            if (item.pid === id) {
                baseList.push(item);
            }
        }
        //递归
        for (let item of baseList) {
            item.chidren = [];
            service.shopList.listThree(list, item.id, item.chidren);
        }
        return baseList;
    }
}

module.exports = ShopListService;
